package com.dwxt.community.controller.supervisor;

import com.dwxt.common.base.*;
import com.dwxt.community.entity.*;
import com.dwxt.community.service.supervisor.*;
import org.apache.commons.lang.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @program: intelligentcity
 * @description: 垃圾袋控制层
 * @create: 2020/04/17
 */
@RestController
@RequestMapping("/cms/supervisorBag")
public class RubbishBagController {

    @Autowired
    private RubbishBagRecordService rubbishBagRecordService;

    /**
     * showdoc
     * @catalog 社区/督导员-巡检员/垃圾袋
     * @title 垃圾袋发放
     * @method  post
     * @param id 必须 String 户主ID
     * @param bagIds 必须 String数组 垃圾袋数组
     * @description  垃圾袋发放
     * @url /cms/supervisorBag/push
     * @return {"status":200,"msg":"SUCCESS","data":null}
     */
    @RequestMapping("/push")
    public BaseResult push(String id, String... bagIds){
        if (StringUtils.isBlank(id)  | bagIds == null || bagIds.length <= 0){
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        return rubbishBagRecordService.push(id,Arrays.asList(bagIds));
    }

    /**
     * showdoc
     * @catalog 社区/督导员-巡检员/垃圾袋
     * @title 垃圾袋溯源
     * @method  get
     * @param id 必须 String 垃圾袋ID
     * @description  垃圾袋溯源
     * @url /cms/supervisorBag/findSource
     * @return {"status":200,"msg":"SUCCESS","data":{"id":"158717938991972","bagId":"0","userId":"158502014539730","supervisorId":"158711800317392","houseAddr":"1,聚金万佳苑,10栋32-6","tdmId":null,"createTime":1587179390000}}
     */
    @RequestMapping("/findSource")
    public BaseResult findSource(String id){
        if (StringUtils.isBlank(id)){
            return BaseResult.build(StatusCode.PARAMETER_WRONG);
        }
        RubbishBagRecord rubbishBagRecord = rubbishBagRecordService.findSource(id);
        return BaseResult.build(rubbishBagRecord != null ? StatusCode.SUCCESS : StatusCode.BAG_NOT_EXIST,rubbishBagRecord);
    }
}
